function invd = invd(x)

% x is a vector

invd = 1./x;
for i=1:length(x)
   if x(i)==0
       invd(i)=0;
   end
end
invd = diag(invd);
return

% Taken directly from the replication package for
% 
% Timmer, Marcel P., Abdul Azeez Erumban, Bart Los, Robert Stehrer, and Gaaitzen J. de Vries.
%  “Slicing Up Global Value Chains.” Journal of Economic Perspectives 28, no. 2 (May 2014): 99–118. 
% https://doi.org/10.1257/jep.28.2.99